import { existsSync, mkdirSync, writeFileSync } from "fs"
import { build } from "node-xlsx"
import { Sheet } from "../interface/excel"

function init() {
    return `
import { line } from "../../interface/excel";
/**
 * @desc 用户自定义输出
 * @param sourceKey 数据源，头行的key值
 * @param line 每行的数据
 * @returns 
 */
export function returnLine(sourceKey: line, line: line): line{
    return line
}
    `
}
let headList = process.argv.slice(2, process.argv.length)
const initXslx: Sheet[] = [
    {
        name: 'sheet1',
        data:[[...headList]],
        options:[]
    }
]
if(existsSync('./custom')){
    writeFileSync('./custom/custom.ts', init(), 'utf-8')
}else{
    mkdirSync('./custom')
    writeFileSync('./custom/custom.ts', init(), 'utf-8')
}

if(existsSync('./data')){
    writeFileSync('./data/模板.xlsx', build(initXslx), 'binary')
}else{
    mkdirSync('./data')
    writeFileSync('./data/模板.xlsx', build(initXslx), 'binary')
}